<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        table {
            margin: 100px auto;
        }
        
        table thead {
            height: 30px;
            width: 200px;
            color: white;
            background-color: gray;
        }
        
        table thead tr th {
            width: 100px;
        }
        
        table tbody {
            height: 30px;
            width: 200px;
        }
        
        table tbody tr td {
            width: 100px;
            height: 35px;
            line-height: 35px;
            text-align: center;
            border: 1px solid gray;
        }
    </style>
</head>

<body>
    <table cellspacing='0'>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>

        <tbody>


        </tbody>
    </table>
    <script>
        // 1.准备好学生数据
        var datas = [{
                name: '001',
                subject: 'javaScript',
                score: 100

            }, {
                name: '002',
                subject: 'javaScript',
                score: 90

            }, {
                name: '003',
                subject: 'javaScript',
                score: 80

            }, {
                name: '004',
                subject: 'javaScript',
                score: 99

            }, {
                name: '005',
                subject: 'javaScript',
                score: 0

            }]
            // 2.往tbody里创建行 有几个人(通过数组的长度)我们就创建几行
        var tbody = document.querySelector('tbody');
        for (var i = 0; i < datas.length; i++) {
            // (1)创建tr行
            var tr = document.createElement('tr');
            tbody.appendChild(tr);
            // (2)行里面创建单元格 td 单元格数量取决于每个对象属性个数for循环遍历对象
            for (var k in datas[i]) {
                //k属性名 obj[k]得到属性值 
                //遍历对象
                var td = document.createElement('td');
                td.innerHTML = datas[i][k];
                tr.appendChild(td);
                //把对象里面的属性值给td
            }
            // (3)创建有删除操作的单元格
            var td = document.createElement('td');
            td.innerHTML = '<a href = "javaScript:;">删除</a>'
            tr.appendChild(td); //给tr添加td
        }
        // 3.删除操作
        var as = document.querySelectorAll('a');
        for (var i = 0; i < as.length; i++) {
            as[i].onclick = function() {
                //点击a删除 删除它爸爸的爸爸 就是行
                tbody.removeChild(this.parentNode.parentNode)
                console.log(this.parentNode);
            }
        }
    </script>
</body>

</html>